<?php


namespace app\api\model;


class Orders extends BaseModel
{
    protected $autoWriteTimestamp = true;
    protected $hidden = ['openid', 'snap_items', 'update_time', 'delete_time'];

    // 读取器将items的json字符串转变json对象
    public function getSnapItemsAttr($value)
    {
        if (empty($value)) {
            return null;
        }
        return json_decode($value);
    }

    public static function getSummaryByUser($uid, $page=1, $size=15)
    {
        $pageDate = self::where('openid', '=', $uid)
            ->order('create_time', 'desc')
            ->paginate($size, true, ['page' => $page]);
        return $pageDate;
    }
}